package com.pmh.hrs.sys.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.pmh.hrs.sys.service.SysCodeService;
import com.pmh.hrs.sys.service.SysMenuService;


@RestController
@RequestMapping("/sys/codes")
public class SysCodeController {

	@Resource(name="sysCodeService")
	private SysCodeService sysCodeService;
	
	/**
	 * 메뉴추가 
	 * @param paramMap
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method =RequestMethod.POST)
	@ResponseStatus(HttpStatus.CREATED)
	public @ResponseBody Map<String,Object> insert( @RequestBody Map<String,Object> paramMap,	HttpServletRequest request) throws Exception{
		
		Map<String,Object> ajaxData = new HashMap<String,Object>();
		sysCodeService.insert(paramMap);
        return ajaxData;
	}
	/**
	 * 메뉴수정 
	 * @param paramMap
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method =RequestMethod.PUT)
	public @ResponseBody Map<String,Object> update( @RequestBody Map<String,Object> paramMap,	HttpServletRequest request) throws Exception{
		
		Map<String,Object> ajaxData = new HashMap<String,Object>();
		sysCodeService.update(paramMap);
		return ajaxData;
	}
	
	
	/**
	 *  메뉴조회 
	 * @param company 회사코드 
	 * @param system  시스템코드 
	 * @param authCd 권한코드
	 * @param screenId 화면ID
	 * @param lvl 화면 레벨
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/{SYSTEM}",method =RequestMethod.GET)
	public @ResponseBody Map<String,Object> selectList(
			@PathVariable(value ="SYSTEM") String system,
			@RequestParam(value ="PRE_CD",required=false) String preCd,
			HttpServletRequest request) throws Exception{
		Map<String,Object> paramMap = new HashMap<String,Object>();
		Map<String,Object> ajaxData = new HashMap<String,Object>();
		
		paramMap.put("SYSTEM", system);
		paramMap.put("PRE_CD", preCd);
		
		List<Map<String,Object>> storeSysMenu = sysCodeService.selectList(paramMap);
		ajaxData.put("SYS_MENU", storeSysMenu);
		
		
		return ajaxData;
	}
	
	/**
	 *  메뉴삭제
	 * @param paramMap
	 * @param system
	 * @param screenId
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method =RequestMethod.DELETE)
	public @ResponseBody Map<String,Object> delete( @RequestBody Map<String,Object> paramMap,
			@RequestParam(value ="SYSTEM") String system,
			@RequestParam(value ="SCREEN_ID") String screenId,
			HttpServletRequest request) throws Exception{
		
		Map<String,Object> ajaxData = new HashMap<String,Object>();
		
			sysCodeService.delete(paramMap);
		
		//List<Map<String,?>> storeUserMst =systemService.select(paramMap);
	//	ajaxData.put("UserInfoMst", storeUserMst);
		return ajaxData;
	}
	
}
